package com.memexue.order.converter;

import com.memexue.core.util.JacksonUtils;
import com.memexue.order.dto.OrderDto;
import com.memexue.order.form.OrderForm;
import com.memexue.order.po.OrderDetail;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class OrderForm2OrderDtoConverter {
    public static OrderDto covert(OrderForm orderForm) throws Exception {
        OrderDto orderDto = new OrderDto();
        orderDto.setBuyerPhone(orderForm.getPhone());
        orderDto.setBuyerName(orderForm.getName());
        orderDto.setBuyerAddress(orderForm.getAddress());
        orderDto.setBuyerOpenid(orderForm.getOpenid());
        List<OrderDetail> orderDetailList = JacksonUtils.json2list(orderForm.getItems(), OrderDetail.class);
        orderDto.setOrderDetailList(orderDetailList);
        return orderDto;
    }
}
